﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.ExpressApp;

namespace Ascent.QiPei.Module.BusinessObjects.Purchase
{
    public partial class PurchasingOrder
    {
        protected override void OnChanged(string propertyName, object oldValue, object newValue)
        {
            base.OnChanged(propertyName, oldValue, newValue);

            switch (propertyName)
            {
                case "TaxIncluded":
                case "TaxRate":
                case "Discount":
                    CalculateAmount();
                    break;
                default:
                    break;
            }
        }

        protected override void DoEndEditAction()
        {
            base.DoEndEditAction();
        }

        private void CalculateAmount()
        {
            DiscountAmount = TotalAmount * Discount / 100;
            if (TaxIncluded)
            {
                TaxAmount = (TotalAmount - DiscountAmount) * TaxRate / 100;
            }
            else
            {
                TaxAmount = 0f;
            }

            Amount = TotalAmount - DiscountAmount - TaxAmount;
        }
    }
}
